Add test for flatbuffers array header - #437
Conversation
|
The created documentation from the pull request is available at: docu-html |
There was a problem hiding this comment.
Pull request overview
This PR adds GoogleTest coverage for the upstream FlatBuffers C++ headers used by score/flatbuffers, specifically targeting flatbuffers/array.h and flatbuffers/allocator.h, and wires the new tests into the Bazel cc_test target.
Changes:
- Add comprehensive unit/fault-injection tests for
flatbuffers/array.hAPIs and specializations. - Add interface/fault-injection tests for
flatbuffers/allocator.h, includingAllocator::reallocate_downward. - Fix and expand
score/flatbuffers:flatbuffers_cpp_library_testsources inscore/flatbuffers/BUILD.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| score/flatbuffers/details/flatbuffers_array_test.cpp | New test suite covering flatbuffers::Array behaviors (casts, iteration, spans, mutation, CopyFromSpan, specialization/death tests). |
| score/flatbuffers/details/flatbuffers_allocator_test.cpp | New test suite validating flatbuffers::Allocator contract and default reallocate_downward behavior (including fault paths). |
| score/flatbuffers/BUILD | Updates flatbuffers_cpp_library_test to use the correct allocator test filename and adds the new array tests. |
Suppressed comments (3)
score/flatbuffers/details/flatbuffers_array_test.cpp:664
- This downcast is undefined behavior: CastToArray(raw) does not produce an ArrayTestAccess<T,N> object, so static_casting the base reference to the derived type is invalid. Use an explicit reinterpret_cast overlay if you need to call the protected overloads.
auto& accessor = static_cast<ArrayTestAccess<int32_t, 3>&>(CastToArray(raw));
score/flatbuffers/details/flatbuffers_array_test.cpp:683
- This downcast is undefined behavior: CastToArray(raw) does not produce an ArrayTestAccess<T,N> object, so static_casting the base reference to the derived type is invalid. Use an explicit reinterpret_cast overlay if you need to call the protected overloads.
auto& accessor = static_cast<ArrayTestAccess<Point, 2>&>(CastToArray(raw));
score/flatbuffers/details/flatbuffers_array_test.cpp:756
- This reinterpret_cast assumes the byte buffer is suitably aligned (and large enough) for Array<Offset, 2>. Use alignas + sizeof(Array<...>) to avoid misalignment/size-related UB.
uint8_t buf[2] = {0};
const auto& arr = *reinterpret_cast<const Array<Offset<void>, 2>*>(buf);
EXPECT_DEATH({ arr[0]; }, "");
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
35ebbe4 to
ffa0e6e
Compare
ffa0e6e to
d16d6a5
Compare
19633fe to
dbbd577
Compare
dbbd577 to
73860ec
Compare
73860ec to
15f5bcf
Compare
15f5bcf to
f5737c8
Compare
|
|
||
| TEST(ArrayCastTest, CastToArray) | ||
| { | ||
| RecordProperty("FullyVerifies", "::flatbuffers::CastToArray"); |
There was a problem hiding this comment.
This way of linking is not acceptable by the process and gets rejected by docs-as-code. It should be a sphinx-needs element, preferably a requirement.
I'm trying to fix some of the flatbuffers tests here: #469
Add test for flatbuffers/array.h.